package org.stvd.service.workflow;

import java.util.List;
import java.util.Map;

import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

/**
 * @Title ProcessCoreService
 * @Destribution 工作流业务层核心接口类
 * @author houzx
 * @date 2020年10月29日
 */
public interface ProcessCoreService {

    public ProcessInstance startInstanceByKey(String processDefinitionKey, String businessKey,
        Map<String, Object> variables);
    
    public boolean deleteProcessInstanceById(String processInstanceId, String deleteReason);
    
    public ActivityImpl findActivitiImpl(String taskId, String activityId) throws Exception;
    
    
    /**
     * 根据当前任务ID，查询可以驳回的任务节点
     * @param taskId 当前任务ID
     */
    public List<ActivityImpl> findBackAvtivity(String taskId) throws Exception;
    /**
     * 根据当前任务ID，查询可以驳回的任务节点
     * @param taskId 当前任务ID
     */
    public List<ActivityImpl> findBackAvtivity(String taskId, ActivityImpl activityImpl, List<ActivityImpl> nextTaskList) throws Exception;
    /**
     * 通过taskId判断该节点是否是会签节点
     * @param taskId
     * @return
     */
    public boolean isJointTask(String taskId);
    /**
     * 审批通过(驳回直接跳回功能需后续扩展)
     * @param taskId 当前任务ID
     * @param variables 流程存储参数
     * @throws Exception
     */
    public void passProcess(String taskId, Map<String, Object> variables) throws Exception;
    /**
     * 通过会签任务节点ID，查询会签子任务
     */
    public List<Task> findJointProcessTask(String taskId);
    /**
     * 驳回流程
     * @param taskId 当前任务ID
     * @param activityId 驳回节点ID
     * @param variables 流程存储参数
     * @throws Exception
     */
    public void backProcess(String taskId, String activityId, Map<String, Object> variables) throws Exception;
    /**
     * 取回流程
     * @param taskId 当前任务ID
     * @param activityId 取回节点ID
     * @throws Exception
     */
    public void callBackProcess(String taskId, String activityId) throws Exception;
    /**
     * 中止流程(特权人直接审批通过等)
     * @param taskId
     */
    public void endProcess(String taskId) throws Exception;
    /**
     * 会签操作
     * @param taskId 当前任务ID
     * @param userCodes 会签人账号集合
     * @throws Exception
     */
    public void jointProcess(String taskId, List<String> userCodes) throws Exception;
    /**
     * 转办流程
     * @param taskId 当前任务节点ID
     * @param userCode 被转办人Code
     */
    public void transferAssignee(String taskId, String userCode, Map<String, Object> variables);

    public TaskEntity findTaskById(String taskId) throws Exception;
    
    public List<Task> findTaskListByKey(String processInstanceId, String key);

    public ProcessInstance findProcessInstanceByTaskId(String taskId) throws Exception;

    public ProcessDefinitionEntity findProcessDefinitionEntityByTaskId(String taskId) throws Exception;

    public ProcessDefinitionEntity findProcessDefinitionEntityById(String processDefinitionId) throws Exception;

    public ProcessDefinition getProcessDefinition(String processDefinitionId) throws Exception;

    public ProcessDefinition getProcessDefinitionByKey(String processDefinitionKey) throws Exception;

    public ProcessInstance getProcessInstance(String processInstanceId) throws Exception;

    public List<HistoricTaskInstance> findHistoryTask(String processInstanceId);

    public ActivityImpl getActivity(String processDefId, String activityId) throws Exception;

    /**
     * 获取下一节点信息
     * @param taskId
     * @return
     */
    public TaskDefinition getNextTaskDefinition(String taskId) throws Exception;
    /**
     * 获取下一节点信息
     * @param activityImpl
     * @param taskId
     * @return
     */
    public List<TaskDefinition> getNextTaskDefinitionList(ActivityImpl activityImpl, String taskId) throws Exception;
    
    /**
     * 获取下一节点任务信息
     * @param taskId
     * @return
     */
    public List<ActivityImpl> getNextTaskInfo(String taskId);
    /**
     * 获取下一节点任务信息
     * @param activityImpl
     * @return
     */
    public List<ActivityImpl> getNextTaskInfo(ActivityImpl activityImpl);
    /**
     * 获取下一节点信息
     * @param nextTaskList
     * @param taskId
     * @return
     */
    public List<PvmTransition> getNextTaskInPvm(List<ActivityImpl> nextTaskList, String taskId);
    /**
     * 获取下一节点信息
     * @param nextTaskList
     * @param activityImpl
     * @return
     */
    public List<PvmTransition> getNextTaskInPvm(List<ActivityImpl> nextTaskList, ActivityImpl activityImpl);
    
    /**
	 * 查找第一个节点
	 * @param processDefinitionId
	 * @return
	 */
    public PvmActivity findFirstActivity(String taskId);
}
